<script setup>
    import { ref } from "vue";
    import { loginOpen } from '@/js/store.js';
	import { debounce, login_api } from '@/js/api.js';

    const forms=ref({name:loginOpen.user.name||'',password:''});
    const onLogin = debounce(async () => {
        if(!forms.value.name || !forms.value.password){
            return;
        }
        try {
            var result = await login_api.post(forms.value); //同步方式
            if (result.state) {
                loginOpen.setUser(result.user, result.token, result.refresh_token);
                loginOpen.loginnum++;
                loginOpen.popup = false;
            }
        } catch (error) {
            console.log("🚀 ~ onLogin ~ error:", error)
        }
    })
</script>

<template>
    <form class="loginform">
        <div class="header">Sign In</div>
        <div class="inputs">
            <input placeholder="用户名" class="input" type="text">
            <input placeholder="密码" class="input" type="password">
        <div class="checkbox-container">
            <label class="checkbox">
            <input type="checkbox" id="checkbox">
            </label>
            <label for="checkbox" class="checkbox-text">Remember me</label>
        </div>
        <button class="sigin-btn">登陆</button>
        <a class="forget" href="#">Forget password ?</a>
        <p class="signup-link">Don't have an account? <a href="#">Sign up</a></p>
        </div>
    </form>

</template>


<style scoped>
.loginform {
  position: relative;
  display: flex;
  flex-direction: column;
  border-radius: 0.75rem;
  background-color: #fff;
  color: rgb(97 97 97);
  box-shadow: 6px 20px 30px rgba(0, 0, 0, .05);
  width: 22rem;
  background-clip: border-box;
  margin: 0 auto;
}

.loginform .header {
  position: relative;
  background-clip: border-box;
  background-color: #1e88e5;
  background-image: linear-gradient(to top right,#187fda,#42a5f5);
  margin: 10px;
  border-radius: 0.75rem;
  overflow: hidden;
  color: #fff;
  box-shadow: 0 0 #0000,0 0 #0000,0 0 #0000,0 0 #0000,rgba(33,150,243,.4);
  height: 7rem;
  letter-spacing: 0;
  line-height: 1.375;
  font-weight: 600;
  font-size: 1.9rem;
  font-family: Roboto, sans-serif;
  display: flex;
  align-items: center;
  justify-content: center;
}

.loginform .inputs {
  padding: 1.5rem;
  gap: 1rem;
  display: flex;
  flex-direction: column;
}

.loginform .input-container {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-width: 200px;
  width: 100%;
  height: 2.75rem;
  position: relative;
}

.loginform .input {
  border: 1px solid rgba(128, 128, 128, 0.61);
  outline: 0;
  color: rgb(69 90 100);
  font-weight: 400;
  font-size: .9rem;
  line-height: 1.25rem;
  padding: 0.75rem;
  background-color: transparent;
  border-radius: .375rem;
  width: 100%;
  height: 100%;
}

.loginform .input:focus {
  border: 1px solid #1e88e5;
}

.loginform .checkbox-container {
  margin-left: -0.625rem;
  display: inline-flex;
  align-items: center;
}

.loginform .checkbox {
  position: relative;
  overflow: hidden;
  padding: .55rem;
  border-radius: 999px;
  display: flex;
  align-items: center;
  cursor: pointer;
  justify-content: center;
  background-color: rgba(0, 0, 0, 0.027);
  height: 35px;
  width: 35px;
}

.loginform .checkbox input {
  width: 100%;
  height: 100%;
  cursor: pointer;
}

.loginform .checkbox-text {
  cursor: pointer;
}

.sigin-btn {
  text-transform: uppercase;
  font-weight: 700;
  font-size: 1rem;
  line-height: 1rem;
  text-align: center;
  padding: .75rem 1.5rem;
  background-color: #1e88e5;
  background-image: linear-gradient(to top right,#1e88e5,#42a5f5);
  border-radius: .5rem;
  width: 100%;
  outline: 0;
  border: 0;
  color: #fff;
}

.signup-link {
  line-height: 1.5;
  font-weight: 300;
  font-size: 0.875rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.signup-link a, .forget {
  line-height: 1.5;
  font-weight: 700;
  font-size: .875rem;
  margin-left: .25rem;
  color: #1e88e5;
}

.forget {
  text-align: right;
  font-weight: 600;
}
</style>